﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class AddDet : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void BtnTj_Click(object sender, EventArgs e)
    {
        string sql = string.Format("select count(*) from Department where Number='{0}' or Name='{1}'", TxtID.Text, TxtName.Text);
        int n = Convert.ToInt32(DBHelper.GetScalar(sql));
        if (n == 0)
        {
            if (TxtID.Text != "" && TxtName.Text != "")
            {
                string insertsql = string.Format("insert into Department (Number,Name,Description) values('{0}','{1}','{2}') ", TxtID.Text, TxtName.Text, TxtDen.Text);
                DBHelper.GetNonQuery(insertsql);
                Response.Write("<script> alert('科室添加成功!') </script>");
                TxtID.Text = "";
                TxtName.Text = "";
                TxtDen.Text = "";
            }
            else
            {
                Response.Write("<script> alert('添加失败,科室信息不能为空!') </script>");
            }
        }
        else
        {
            Response.Write("<script> alert('添加失败，请输入正确的科室信息!') </script>");
            TxtID.Text = "";
            TxtName.Text = "";
            TxtDen.Text = "";
        }
    }

    protected void BtnQk_Click(object sender, EventArgs e)
    {
        TxtDen.Text = "";
        TxtID.Text = "";
        TxtName.Text = "";
    }

    protected void TxtID_TextChanged(object sender, EventArgs e)
    {
        string sql = string.Format("select * from Department where Number='{0}'", TxtID.Text);
        int n= Convert.ToInt32(DBHelper.GetScalar(sql));
        if (n != 0)
        {
            lblTs.Text = "科室编号已存在。";
        }
        else
        {
            lblTs.Text = "";
        }
    }

    protected void TxtName_TextChanged(object sender, EventArgs e)
    {
        string sql = string.Format("select * from Department where Name='{0}'", TxtName.Text);
        int n = Convert.ToInt32(DBHelper.GetScalar(sql));
        if (n != 0)
        {
            lblName.Text = "科室名称已存在。";
        }
        else
        {
            lblName.Text = "";
        }
    }
}